package com.dj.mingkong.portal.biz.controller.music;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dj.mingkong.common.annotation.RequestLimit;
import com.dj.mingkong.common.infrastructure.base.dto.page.PageVo;
import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import com.dj.mingkong.common.microservice.UserContext;
import com.dj.mingkong.common.util.AssertUtils;
import com.dj.mingkong.common.util.SmartBeanCopy;
import com.dj.mingkong.portal.biz.controller.music.vo.request.AlbumLikeAddVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.AlbumLikeQueryVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.AlbumLikeVo;
import com.dj.mingkong.portal.biz.service.music.AlbumLikeService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 专辑点赞管理
 *
 * @author zenglonghui
 * @date: 2023/2/3 12:32
 */
@RestController
@RequestMapping("/album/like")
public class AlbumLikeController {
    @Resource
    private AlbumLikeService albumLikeService;


    /**
     * 专辑点赞
     *
     * @param addVo {}
     * @return Boolean
     */
    @PostMapping("/add")
    @RequestLimit(count = 5)
    public RestResponse<Boolean> add(@RequestBody @Validated AlbumLikeAddVo addVo) {
        albumLikeService.add(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 分页查询我的点赞专辑
     *
     * @param queryVo {}
     * @return AlbumVo
     */
    @PostMapping("/pageByVo")
    public RestResponse<PageVo<AlbumLikeVo>> pageByVo(@RequestBody AlbumLikeQueryVo queryVo) {
        AssertUtils.checkQueryPageVo(queryVo);
        queryVo.setUserId(UserContext.getUserId());
        final Page<AlbumLikeVo> albumLikeVoPage = albumLikeService.pageByVo(queryVo);
        final PageVo<AlbumLikeVo> pageVo = SmartBeanCopy.copyPageVo(albumLikeVoPage, AlbumLikeVo.class);
        return RestResponse.success(pageVo);
    }
}
